package tree.structure.huffman;

/**
 * @author: 26233
 * @create: 2022-07-25 15:29:22
 * @Description
 **/

public class HuffmanTreeNode {

    private HuffmanTreeNode left;
    private HuffmanTreeNode right;
    private int weight;
    private int topWeight;

    public HuffmanTreeNode() {
    }

    public HuffmanTreeNode(int weight) {
        this.weight = weight;
    }

    public int getWeight() {
        return weight;
    }

    public void setWeight(int weight) {
        this.weight = weight;
    }

    public int getTopWeight() {
        return topWeight;
    }

    public void setTopWeight(int topWeight) {
        this.topWeight = topWeight;
    }

    public HuffmanTreeNode getLeft() {
        return left;
    }

    public HuffmanTreeNode getRight() {
        return right;
    }

    public static HuffmanTreeNode genNode(int weight) {
        HuffmanTreeNode huffmanTreeNode = new HuffmanTreeNode(weight);
        huffmanTreeNode.setTopWeight(huffmanTreeNode.getWeight());

        return huffmanTreeNode;
    }

    public static HuffmanTreeNode genNode(HuffmanTreeNode leftNode, HuffmanTreeNode rightNode) {
        HuffmanTreeNode huffmanTreeNode = new HuffmanTreeNode(leftNode.getWeight() + rightNode.getWeight());
        huffmanTreeNode.setTopWeight(huffmanTreeNode.getWeight());

        huffmanTreeNode.left = leftNode;
        huffmanTreeNode.right = rightNode;

        return huffmanTreeNode;
    }
}
